interface BaseTimerCallBack {
    (BaseTimer): void
}

export class BaseTimer {
    TIMER_ID: number;
    count: number = 0;

    clearTimer() {
        clearInterval(this.TIMER_ID);
    }

    constructor(initCount: number, callback: BaseTimerCallBack, timeout: number) {
        this.count = initCount;
        this.TIMER_ID = this.run(callback, timeout);
    }


    private run(callback: BaseTimerCallBack, timeout: number): number {
        return setInterval(() => {
            this.count--;
            callback(this);
            if (this.count === 0) {
                this.clearTimer();
            }
        }, timeout);
    }
}

 //默认验证码倒计时
export const DEFAULT_VERIFICATION_TIME_OUT = 60;